﻿<%@ Page Title="gatewayinfo" Language="C#" MasterPageFile="~/EasyUI.master" AutoEventWireup="true" CodeBehind="List.aspx.cs" Inherits="jnlamp.Web.gatewayinfo.List" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=6a5e0746feee514e8bb7b3f468a626d1"></script>
    <script src="../Script/TextIconOverlay_min.js"></script>
    <script src="../Script/MarkerClusterer_min.js"></script>
    <script src="../Script/jnbase.js"></script>
    <script src="../Script/datetime.js"></script>
    <script type="text/javascript">
        var pt;
        var ptmark;
        var uid = "";
        var map;
        var bid = "";
        var city = "";
        var icon1 = new BMap.Icon('../images/map1.gif', new BMap.Size(18, 34), { anchor: new BMap.Size(9, 34) });
        var ply;//区域线
        var loc;//选择点的地址
        var jd = "";
        var wd = "";
        var markerClusterer;
        var markers = [];
        var data_info;
        var label;
        $.extend($.fn.tree.methods, {
            getLevel: function (jq, target) {
                var l = $(target).parentsUntil("ul.tree", "ul");
                return l.length + 1;
            }
        });
        $(function () {
            bid = getUrlParam('bid');
            InitMap();
            InitA();
            InitGird();
            InitSearch();
            $.extend($.fn.validatebox.defaults.rules, {
                gwid: {
                    validator: function (value) {
                        var flag;
                        if ($("#test").val() == "add") {
                            $.ajax({
                                type: 'POST',
                                url: 'GetGate.ashx',
                                data: 'gwid=' + value + '&action=exist',
                                async: false,
                                success: function (data) {
                                    if (data == 'F') {
                                        flag = true;
                                    } else {
                                        flag = false;
                                    }
                                }
                            });
                        }
                        else {
                            if ($('#ogwid').val() != value) {
                                $.ajax({
                                    type: 'POST',
                                    url: 'GetGate.ashx',
                                    data: 'gwid=' + value+'&action=exist',
                                    async: false,
                                    success: function (data) {
                                        if (data == 'F') {
                                            flag = true;
                                        } else {
                                            flag = false;
                                        }
                                    }
                                });

                            }
                            else {
                                flag = true;
                            }
                        }
                        return flag;
                    },
                    message: '您输入的网关ID已存在，请更换。'
                }
            });
        });
        function InitA() {
            city = getUrlParam('city');
            city = decodeURI(decodeURI(city));
            map.clearOverlays();
            getBoundary(city);

        }
        function InitMap() {
            map = new BMap.Map("mymap");          // 创建地图实例 
            map.addControl(new BMap.MapTypeControl());   //添加地图类型控件
            map.centerAndZoom(city, 13);
            map.enableScrollWheelZoom(true);
            var top_left_control = new BMap.ScaleControl({ anchor: BMAP_ANCHOR_TOP_LEFT });// 左上角，添加比例尺
            var top_left_navigation = new BMap.NavigationControl();  //左上角，添加默认缩放平移控件
            map.addControl(top_left_control);
            map.addControl(top_left_navigation);
            var geoc = new BMap.Geocoder();
            map.addEventListener("click", function (e) {
                if (ptmark != null) {
                    ptmark.hide();
                    ptmark = "";
                }
                pt = e.point;
                jd = e.point.lng;
                wd = e.point.lat;
                //geoc.getLocation(pt, function (rs) {
                //    var addComp = rs.addressComponents;
                //    loc = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;
                //});
                ptmark = new BMap.Marker(pt)
                map.addOverlay(ptmark);
            });
        }
        //初始化表格
        function InitGird() {
            $('#tt').datagrid({
                title: '网关列表', //表格标题
                url: 'GetGate.ashx', //请求数据的页面
                sortName: 'gwdate', //排序字段
                idField: 'gid', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
                //height: $(parent.document).find("#mainPanle").height() - 35 > 0 ? $(parent.document).find("#mainPanle").height() - 35 : 500, //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                singleSelect: true,
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                method: 'post',
                columns: [[
                    { field: 'ckb', checkbox: true },
                    { title: '网关编号', field: 'gwid', width: 60 },
                    { title: '通道', field: 'gchannel', width: 40 },
                    { title: '流量卡号', field: 'gwphone', width: 60 },
                    { title: '网关备注', field: 'gwmark', width: 60 },
                    {
                        title: '安装时间', field: 'gwdate', width:100, formatter: function (value, row, index) {
                            if (value != "") {

                                if (value.indexOf("-") != -1)
                                    value = value.replace(/-/g, "/");
                                return new Date(value).pattern("yyyy年M月d日");
                            }
                        }
                    },
                    {
                        title: '灯设置', field: 'a', width: 100, formatter: function (value, row, index) {
                            return '<a href="#" onclick="top.addTab(\'' + row.gwid + '\',\'/lampinfo/list.aspx?gid=' + row.gid + '&gwid=' + row.gwid + '&gwd=' + row.gwd + '&gjd=' + row.gjd + '\', \'icon icon-magic\');">灯设置</a>';
                        }
                    }
                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "query", "bid": bid },
                onClickRow: function (rowIndex, rowData) {
                    map.centerAndZoom(new BMap.Point(rowData.gjd, rowData.gwd), 14);
                },
                onLoadSuccess: function (data) {
                    map.clearOverlays();
                    getBoundary(city);
                    data_info = [];
                    $.each(data.rows, function (k, v) {
                        data_info.push({ "lng": v["gjd"], "lat": v["gwd"], "gwid": v["gwid"], "gchannel": v["gchannel"], "gwphone": v["gwphone"] });
                    });
                    var mlevel;
                    var marker;
                    var ptt = "";
                    if (markers.length > 0) {
                        if (markerClusterer != null) {
                            markerClusterer.removeMarkers(markers);
                            markerClusterer = null;
                        }
                        markers = [];
                    }
                    for (var i = 0; i < data_info.length; i++) {                        
                        ptt = new BMap.Point(data_info[i].lng, data_info[i].lat);
                        marker = new BMap.Marker(ptt, { icon: icon1 });
                        map.addOverlay(marker);
                        label = new BMap.Label(data_info[i].gwid, { offset: new BMap.Size(20, -10) });
                        marker.setLabel(label);
                        markers.push(marker);
                    }
                    if (markers.length > 0)
                        markerClusterer = new BMapLib.MarkerClusterer(map, { markers: markers });//对地图扩大缩小后会都所有的点全显示出来。

                },
                pagination: true, //是否开启分页
                pageList: [10, 20, 30, 40, 50],
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true //行号
            });
        }
        function addClickHandler(content, marker) {
            marker.addEventListener("click", function (e) {
                openInfo(content, e);
            }
            );
        }
        function openInfo(content, e) {
            var p = e.target;
            var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
            var infoWindow = new BMap.InfoWindow(content);
            map.openInfoWindow(infoWindow, point);
        }
        function getQueryParams(queryParams) {
            if (sebm != "")
                queryParams.sebm = sebm;
            return queryParams;

        }

        function reloadgrid() {
            var queryParams = $('#tt').datagrid('options').queryParams;
            getQueryParams(queryParams);
            $('#tt').datagrid('options').queryParams = queryParams;
            $("#tt").datagrid('reload');
        }
        function InitSearch() {
            $("#ipt_search").searchbox({
                width: 200,
                searcher: function (val, name) {
                    $('#tt').datagrid('options').queryParams.search_type = name;
                    $('#tt').datagrid('options').queryParams.search_value = val;
                    $('#tt').datagrid('reload');
                },
                prompt: '请输入ID'
            });
        }
        function newUser() {
            if (jd == "") {
                $.messager.alert("提示", "请选择设备标注点！", "info");
                return;
            }
            if (bid == "") {
                $.messager.alert("提示", "没有对应的基地！", "info");
                return;
            }
            $('#fm').form('clear');
            $("#gjd").val(jd);
            $("#gwd").val(wd);
            $("#bid").val(bid);
            $('#dlg').dialog('open').dialog('setTitle', '添加网关');
            document.getElementById("test").value = "add";
        }

        function editUser() {
            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要修改的行！", "info");
            }
            if (row) {
                $('#dlg').dialog('open').dialog('setTitle', '修改类别');
                document.getElementById("test").value = "modify";
                $('#ogwid').val(row.gwid);
                $('#fm').form('load', row);
            }
        }
        //添加        
        function saveUser() {
            var test = document.getElementById("test").value;
            var f = $('#fm');
            if (test == "add") {
                f.form('submit', {
                    url: "GetGate.ashx?action=" + test,
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        if (result.indexOf("T") == 0) {
                            $('#dlg').dialog('close');
                            $.messager.alert("提示", "恭喜您，信息添加成功", "info");
                            $('#tt').datagrid('reload');
                        }
                        else if ((result.indexOf("F") == 0)) {
                            $.messager.alert("提示", "添加失败，请重新操作！", "info");
                            return;
                        }
                        else if ((result.indexOf("L") == 0)) {
                            $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                            top.location = '/index.aspx';
                            return;
                        }
                    }
                });

            } else {
                $('#fm').form('submit', {
                    url: "GetGate.ashx?action=" + test,
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        if (result.indexOf("T") == 0) {
                            $('#dlg').dialog('close');
                            $('#tt').datagrid('clearSelections');
                            $.messager.alert("提示", "恭喜您，信息修改成功", "info");
                            $('#tt').datagrid('reload');
                        }
                        else if ((result.indexOf("F") == 0)) {
                            $.messager.alert("提示", "添加失败，请重新操作！", "info");
                            return;
                        }
                        else if ((result.indexOf("L") == 0)) {
                            $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                            top.location = '/index.aspx';
                            return;
                        }
                    }
                });
            }
        }
        function removeUser() {
            var test = document.getElementById("test").value = "delete";
            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要删除的行！", "info");
            }
            if (row) {
                $.messager.confirm('提示', '你确定要删除这条信息吗？', function (r) {
                    if (r) {
                        $('#fm').form('submit', {
                            url: 'GetGate.ashx?gid=' + row.gid + '&gwid='+row.gwid+'&action=' + test,
                            onSubmit: function () {
                                
                            },
                            success: function (result) {
                                if (result.indexOf("T") == 0) {
                                    $('#dlg').dialog('close');
                                    $('#tt').datagrid('clearSelections'); //清空选中的行  
                                    $.messager.alert("提示", "恭喜您，信息删除成功！", "info");
                                    $('#tt').datagrid('reload');
                                }
                                else if ((result.indexOf("F") == 0)) {
                                    $.messager.alert("提示", "删除失败，请删除网关下的灯再重新操作！", "info");
                                    return;
                                }
                                else if ((result.indexOf("L") == 0)) {
                                    $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                                    top.location = '/index.aspx';
                                    return;
                                }
                            }
                        });
                    }
                })
            }
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="easyui-layout" style="width: 100%; height: 100%;">
        <div region="center" style="background: #eee; overflow: auto">
            <div class="easyui-layout" data-options="fit:true">
                <div region="west" split="true" style="width: 450px; overflow: auto">
                    <table id="tt">
                    </table>
                    <div id="tab_toolbar" style="padding: 4px;">
                        <table cellpadding="0" cellspacing="0" style="width: 100%">
                            <tr>
                                <td style="padding-left: 2px">
                                    <a href="#" onclick="newUser();" id="a_add"
                                        class="easyui-linkbutton" iconcls="icon-add">添加</a>
                                    <a href="javascript:void(0)" onclick="editUser() " class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>
                                    <a href="#" onclick="removeUser();return false;" id="a_del" class="easyui-linkbutton" iconcls="icon-cancel">删除</a>

                                </td>
                                <td style="text-align: right; padding-right: 15px">
                                    <input id="ipt_search" menu="#search_menu" />
                                    <div id="search_menu" style="width: 200px">
                                        <div name="usernum">
                                            网关ID
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div id="dlg" class="easyui-dialog" style="width: 400px; height: auto; padding: 10px 20px"
                        data-options="closed:true,buttons:'#dlg-buttons',shadow:false">
                        <form id="fm" method="post" enctype="multipart/form-data">
                            <div class="fitem">
                                <label>设备ID：</label>
                                <input name="gwid" id="gwid" class="easyui-validatebox" data-options="required:true,validType:'gwid'" />
                                <input name="test" id="test" type="hidden" />
                                <input name="gid" id="gid" type="hidden" />
                                <input name="gjd" id="gjd" type="hidden" />
                                <input name="gwd" id="gwd" type="hidden" />
                                <input name="bid" id="bid" type="hidden" />
                                <input name="ogwid" id="ogwid" type="hidden" />
                                
                            </div>
                            <div class="fitem">
                                <label>信道编号：</label>
                                <input name="gchannel" id="gchannel" class="easyui-validatebox" data-options="required:true" />
                            </div>
                            <div class="fitem">
                                <label>流量卡号：</label>
                                <input name="gwphone" id="gwphone" class="easyui-validatebox" data-options="required:true" />
                            </div>
                            <div class="fitem">
                                <label>创建日期：</label>
                                <input id="gwdate" name="gwdate" class="easyui-datetimebox" data-options="required:true" />
                            </div>
                            <div class="fitem" style="height: 80px;">
                                <label>备注：</label>
                                <textarea name="gwmark" id="gwmark" style="height: 60px; width: 200px;"></textarea>

                            </div>


                        </form>
                    </div>
                    <div id="dlg-buttons">
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveUser()">保存</a>
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
                    </div>
                </div>
                <div region="center" style="background: #eee; overflow: auto;">
                    <div style="width: 100%; height: 100%; overflow: hidden; margin: 0;position: relative;">
                        <div id="mymap" style="width: 100%; height: 100%; overflow: hidden; margin: 0;"></div>
                        <div id="Maptype" style=" position: absolute; right:40px; top: 50px; z-index: 99; color: Black; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px;">
                            <input id="CBstationname" onclick="ShowstationName('checkbox')" checked="checked" style="float: left; margin-left: 10px;"
                                type="checkbox" />
                            <label onclick="ShowstationName('label')" style="float: left; text-align: left; font-size: 13px; font-family: 宋体; font-weight: bold; margin-top: 3px; cursor: pointer;">
                                显示名称</label>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</asp:Content>

